<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
      <?php
        $ban = input('ban', false);
        $userActive = '';
        $banActive = '';
        if ($ban) {
          $banActive = 'active';
        } else {
          $userActive = 'active';
        }
      ?>
        <li class="{$userActive}"><a href="{:url('index')}">{:lang('USER_INDEXADMIN_INDEX')}</a></li>
        <li class="{$banActive}"><a href="{:url('index')}?ban=1">拉黑用户</a></li>
        <li><a href="{:url('info_auditing')}">信息审核</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('user/adminIndex/index')}">
        用户ID：
        <input class="form-control" type="text" name="uid" style="width: 200px;" value="{:input('request.uid')}"
               placeholder="请输入用户ID">
        关键字：
        <input class="form-control" type="text" name="keyword" style="width: 200px;" value="{:input('request.keyword')}"
               placeholder="姓名/手机">
        公司：
        <input class="form-control" type="text" name="company" style="width: 200px;" value="{:input('request.company')}"
                placeholder="公司">
        门店：
        <input class="form-control" type="text" name="subsidiary" style="width: 200px;" value="{:input('request.subsidiary')}"
                        placeholder="门店">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('user/adminIndex/index')}">清空</a>
    </form>
    <form method="post" class="js-ajax-form">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>ID</th>
                <th>{:lang('USERNAME')}</th>
                <th>姓名</th>
                <th>手机</th>
                <th>公司</th>
                <th>分店</th>
                <th>{:lang('REGISTRATION_TIME')}</th>
                <th>{:lang('STATUS')}</th>
                <th>{:lang('ACTIONS')}</th>
            </tr>
            </thead>
            <tbody>
            <php>
                $user_statuses=array("0"=>lang('USER_STATUS_BLOCKED'),"1"=>lang('USER_STATUS_ACTIVATED'),"2"=>'审核中');
            </php>
            <foreach name="list" item="vo">
              <?php $more = json_decode($vo['more'], true); ?>
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo['user_login']?$vo['user_login']:($vo['mobile']?$vo['mobile']:lang('THIRD_PARTY_USER'))}
                    </td>
                    <td>{$vo['user_nickname']?$vo['user_nickname']:lang('NOT_FILLED')}</td>
                    <td>{$vo.mobile}</td>
                    <td><?php if (isset($more['company'])) echo $more['company']; ?></td>
                    <td><?php if (isset($more['subsidiary'])) echo $more['subsidiary']; ?></td>
                    <td>{:date('Y-m-d H:i:s',$vo['create_time'])}</td>
                    <td>{$user_statuses[$vo['user_status']]}</td>
                    <td>
                      <a
                        href="javascript:doEditUser('{:url('edit',array('id'=>$vo.id))}');"
                      >修改</a>
                      <?php if ($vo['user_status'] == 2) { ?>
                        <a
                          href="{:url('adminIndex/pass',array('id'=>$vo['id']))}"
                          class="js-ajax-dialog-btn"
                          data-msg="确定通过该会员吗？"
                        >审核</a>
                      <?php } ?>
                        <neq name="vo.id" value="1">
                            <empty name="vo.user_status">
                                <a href="{:url('adminIndex/cancelban',array('id'=>$vo['id']))}"
                                   class="js-ajax-dialog-btn"
                                   data-msg="{:lang('ACTIVATE_USER_CONFIRM_MESSAGE')}">{:lang('ACTIVATE_USER')}</a>
                                <else/>
                                <a href="{:url('adminIndex/ban',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn"
                                   data-msg="{:lang('BLOCK_USER_CONFIRM_MESSAGE')}">{:lang('BLOCK_USER')}</a>
                            </empty>
                            <else/>
                            <a style="color: #ccc;">{:lang('BLOCK_USER')}</a>
                        </neq>
                        <a
                          href="{:url('adminIndex/remove',array('id'=>$vo['id']))}"
                          class="js-ajax-dialog-btn"
                          data-msg="确定删除该会员吗？"
                        >删除</a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
        <div class="pagination">{$page}</div>
    </form>
</div>

<script type="text/javascript">
  function doEditUser(url) {
      openIframeLayer(url, '修改信息', {
          area: ['450px', '385px'],
          btn: ['确定', '取消'],
          yes: function (index, layero) {
              //do something

              var iframeWin = window[layero.find('iframe')[0]['name']];
              var data = iframeWin.getForm();
              editForm(data.url, data.formData);

              layer.close(index); //如果设定了yes回调，需进行手工关闭
          }
      });
  };

  function editForm (url, formData) {
    $.post(url, formData, function (data) {
      var _refresh = function() {
          if (data.url) {
              //返回带跳转地址
              window.location.href = data.url;
          } else {
              if (data.code == 1) {
                  //刷新当前页
                  reloadPage(window);
              }
          }
      }

      function _refresh() {
          if (data.url) {
              //返回带跳转地址
              window.location.href = data.url;
          } else {
              if (data.code == 1) {
                  //刷新当前页
                  reloadPage(window);
              }
          }
      }

      if (data.code == 1) {
          noty({
              text: data.msg,
              type: 'success',
              layout: 'topCenter',
              modal: true,
              // animation: {
              //     open: 'animated bounceInDown', // Animate.css class names
              //     close: 'animated bounceOutUp', // Animate.css class names
              // },
              timeout: 800,
              callback: {
                  afterClose: function () {
                    _refresh();
                  }
              }
          }).show();
          $(window).focus();
      } else if (data.code == 0) {
          noty({
              text: data.msg,
              type: 'error',
              layout: 'topCenter',
              modal: true,
              // animation: {
              //     open: 'animated bounceInDown', // Animate.css class names
              //     close: 'animated bounceOutUp', // Animate.css class names
              // },
              timeout: 800,
              callback: {
                  afterClose: function () {
                      _refresh();
                  }
              }
          }).show();
          $(window).focus();
      }
    })
  };
</script>

<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
